using System.Collections;
using System.Collections.Generic;
using System.Xml;

namespace System.Web.Core
{
    public class Command
    {
        private string commandIdent;
        private string commandName;
        private Hashtable commandParameters = new Hashtable();
        private List<ReturnEntity> returnEntities = new List<ReturnEntity>();

        public Command()
        {
        }
        public Command(XmlNode commandNode)
        {
            this.commandIdent = commandNode.Attributes["commandId"].Value;
            this.commandName = commandNode.Attributes["commandName"].Value;

            CommandParameter commandParameter = null;
            foreach (XmlNode parameterNode in commandNode.SelectSingleNode("parameters").ChildNodes)
            {
                commandParameter = new CommandParameter();

                commandParameter.ClassMember = parameterNode.Attributes.GetNamedItem("classMember").Value;
                commandParameter.ParameterName = parameterNode.Attributes.GetNamedItem("parameterName").Value;
                commandParameter.DbTypeHint = parameterNode.Attributes.GetNamedItem("dbTypeHint").Value;
                commandParameter.ParamDirection = parameterNode.Attributes.GetNamedItem("paramDirection").Value;

                Parameters[commandParameter.ClassMember] = commandParameter;
            }

            XmlNode returnEntityCollectionNode = commandNode.SelectSingleNode("returnEntityCollection");
            if (returnEntityCollectionNode != null)
            {
                foreach (XmlNode returnEntityNode in returnEntityCollectionNode.ChildNodes)
                {
                    ReturnEntities.Add(new ReturnEntity(returnEntityNode));
                }
            }
        }

        public string CommandIdent
        {
            get
            {
                return commandIdent;
            }
            set
            {
                commandIdent = value;
            }
        }
        public string CommandName
        {
            get
            {
                return commandName;
            }
            set
            {
                commandName = value;
            }
        }
        public Hashtable Parameters
        {
            get
            {
                return commandParameters;
            }
        }
        public List<ReturnEntity> ReturnEntities
        {
            get
            {
                return returnEntities;
            }
        }
    }
}
